package com.asset.dispoal.nature.service;


import com.asset.dispoal.nature.api.GbNatureService;
import com.asset.dispoal.nature.dto.requset.GbNatureRequest;
import com.asset.dispoal.nature.dto.response.GbNatureResponse;
import com.asset.dispoal.nature.service.commom.DeleteNatureCommand;
import com.asset.dispoal.nature.service.commom.InsertNatureCommand;
import com.asset.dispoal.nature.service.commom.QueryAllNatureCommand;
import com.asset.dispoal.nature.service.commom.UpdateNatureCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

/**
 * 性质管理服务接口
 *
 * @author: mhuang
 * @date: 2022-02-25 13:21:21
 */
@Service
public class IGbNatureServiceImpl implements GbNatureService {

    @Autowired
    DeleteNatureCommand deleteNatureCommand;

    @Autowired
    InsertNatureCommand insertNatureCommand;

    @Autowired
    UpdateNatureCommand updateNatureCommand;

    @Autowired
    QueryAllNatureCommand queryAllNatureCommand;


    @Override
    public Result insert(GbNatureRequest gbNatureRequest) {
        return insertNatureCommand.execute(gbNatureRequest);
    }

    @Override
    public void delete(GbNatureRequest request) {
        deleteNatureCommand.execute(request);
    }

    @Override
    public Result update(GbNatureRequest gbNatureRequest) {
        return updateNatureCommand.execute(gbNatureRequest);
    }

    @Override
    public Result<PageVO<GbNatureResponse>> queryPage(GbNatureRequest gbNatureRequest) {

        final List<GbNatureResponse> execute = queryAllNatureCommand.execute(gbNatureRequest);
        final List<GbNatureResponse> gbNatureResponses = execute.subList(
                gbNatureRequest.getStart() - 1,
                gbNatureRequest.getRows() - 1 > execute.size() ? execute.size() : gbNatureRequest.getRows());
        PageVO<GbNatureResponse> pageVO = new PageVO<>();
        pageVO.setResult(gbNatureResponses);
        pageVO.setTotalSize(gbNatureResponses.size());
        return Result.ok(pageVO);
    }
}